#pragma once
#include <lcir/IR/Context.h>
#include <lcir/IR/Operand.h>
#include <lcir/IR/Value.h>

#include <vector>
namespace lcir {
class Expression;

// trait，这个是个空类，辅助类型判断
class ExprTempInstance {
 public:
  template <class T>
  static ExprTempInstance *get() {
    return GlobalContext::get()->getExprTempInstance<T>();
  }
};

// expression 模板，作用是按照某一方式去解释expression的各个操作数
class ExprTemplate {
 protected:
  Expression *expr{nullptr};
  ExprTempInstance *instance{nullptr};
  std::vector<Operand *> operands;
  std::vector<Value *> results;

 public:
  ExprTemplate(Expression *expr, ExprTempInstance *instance);
  ExprTemplate() = delete;
  ExprTempInstance *getInstance() { return instance; }
};

template <class DerivedTy>
class ExprTempCRTP : public ExprTemplate {
 public:
  ExprTempCRTP(Expression *expr) : ExprTemplate(expr, ExprTempInstance::get<DerivedTy>()) {}
};

}  // namespace lcir